$().ready(function () {
    $('#login').click(function () {
        $.ajax({
            type: "POST",
            url: "/index.php?m=home&c=user&a=login",
            dataType: 'JSON',
            data:{
              'username':$("#username").val(),
              'password':$("#password").val()
            },
            success: function(data){
               if(data.errno == "30002") {
                   layer.msg("用户不存在");
               }else if(data.errno == "30003") {
                   layer.msg("密码错误");
               }else{
                   var option = {'path':'/', 'expires': 86400};
                   var access_token = data.access_token;
                   tool.cookie('access_token', access_token, option);
                   if(data.user.type == 1) {
                       window.location.href = "/index.php?m=home&c=Index&a=admin";
                   }
               }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
            }
        });

    })
})